
import {Stack} from '../struct/stack'
import {TreeNode} from '../struct/tree'

let tree = new TreeNode(1)
let tree2 = new TreeNode(2)
let tree3 = new TreeNode(3)
let tree4 = new TreeNode(4)
let tree5 = new TreeNode(5)
let tree6 = new TreeNode(6)
let tree7 = new TreeNode(7)

tree.left = tree2
tree.right = tree3

tree2.left = tree4
tree2.right = tree5

tree3.left = tree6
tree3.right = tree7

const s = new Stack()
const arr = []

// function preOrderTree(root) {
//   while(root) {
//     while(root || s.empty()) {
//       s.in(root)
//       arr.push(root.val)
//       root = root.left
//     }

//     root = s.peek()
//     s.out()
//     root = root.right
//   }
// }

// function preOrderTree(root) {
//   if (root) {
//     arr.push(root.val)
//     preOrderTree(root.left)
//     preOrderTree(root.right)
//   } 

//   return
// }

// preOrderTree(tree)
// console.log(arr)

// let mid 
// let res = true

// function isBinarySTree(root, tag = 0) {

//   if (root) {
    
//     if (!mid) {
//       mid = root.val
//       isBinarySTree(root.left, -1)
//       isBinarySTree(root.right, 1)
//     } else {

//       const current = root.val
//       if ( tag == -1 ? current < mid : current > mid  ) {
//         mid = current
//         isBinarySTree(root.left, -1)
//         isBinarySTree(root.right, 1)
//       } else {
//         return res = false
//       }
//     }
//   } 

//   return 

// }

const t = new TreeNode(5)
const t0 = new TreeNode(5)
const t1 = new TreeNode(4.5) 
const t2 = new TreeNode(3)
const t3 = new TreeNode(4.6)

const t4 = new TreeNode(6)
const t5 = new TreeNode(7)

t.left = t1
t1.right = t3
t1.left= t2

t.right = t4
t4.right = t5

t0.left = t1
t0.right = t4

// isBinarySTree(t)
// console.dir(t);
// console.log(res)
let res = true
function isSameBinary(root1, root2, left, right) {

  if (!root1) {
    if (root2) {
      return res = false
    }

    return 
  }

  if (!(root2.val <= right && root2.val >= left)) {
    
    return res = false
  }

  isSameBinary(root1.left, root2.left, left, root1.val)
  isSameBinary(root1.right, root2.right, root1.val, right)
} 

isSameBinary(t, t0, -Infinity, Infinity)
isSameBinary(t0, t, -Infinity, Infinity)

console.log(t)
console.log(t0)
console.log(res)
export default {}